const https = require('https');

// 测试Write API
console.log('测试Write API...');
const writeApiTest = () => {
  const options = {
    hostname: 'localhost',
    port: 7002,
    path: '/weatherforecast',
    method: 'GET',
    rejectUnauthorized: false
  };

  const req = https.request(options, (res) => {
    console.log(`Write API状态码: ${res.statusCode}`);
    let data = '';
    res.on('data', (chunk) => {
      data += chunk;
    });
    res.on('end', () => {
      console.log('Write API响应:', data);
    });
  });

  req.on('error', (e) => {
    console.error('Write API错误:', e.message);
  });

  req.end();
};

// 测试Read API
console.log('测试Read API...');
const readApiTest = () => {
  const options = {
    hostname: 'localhost',
    port: 7001,
    path: '/weatherforecast',
    method: 'GET',
    rejectUnauthorized: false
  };

  const req = https.request(options, (res) => {
    console.log(`Read API状态码: ${res.statusCode}`);
    let data = '';
    res.on('data', (chunk) => {
      data += chunk;
    });
    res.on('end', () => {
      console.log('Read API响应:', data);
    });
  });

  req.on('error', (e) => {
    console.error('Read API错误:', e.message);
  });

  req.end();
};

// 测试商品API
console.log('测试商品API...');
const productApiTest = () => {
  const options = {
    hostname: 'localhost',
    port: 7001,
    path: '/api/Product/get-products',
    method: 'GET',
    rejectUnauthorized: false
  };

  const req = https.request(options, (res) => {
    console.log(`商品API状态码: ${res.statusCode}`);
    let data = '';
    res.on('data', (chunk) => {
      data += chunk;
    });
    res.on('end', () => {
      console.log('商品API响应:', data);
    });
  });

  req.on('error', (e) => {
    console.error('商品API错误:', e.message);
  });

  req.end();
};

// 执行测试
setTimeout(writeApiTest, 1000);
setTimeout(readApiTest, 2000);
setTimeout(productApiTest, 3000); 